/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2020-06-22 10:20:09
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-10 10:38:33
 */
import React from 'react';
import { inject, observer } from 'mobx-react';
import { message, Button } from 'antd';
import { WeaLocaleProvider, WeaDialog, WeaFormItem, WeaInput } from 'ecCom';
import * as dialogTypes from '../../../constants/OdocCompsDialogType';

const getLabel = WeaLocaleProvider.getLabel;

const itemWrapper = {
  labelCol: { span: 6 },
  wrapperCol: { span: 18 },
};


@inject('odocRequestStore')
@observer
class Main extends React.Component {
  constructor(props) {
    super(props);

    this.closeDialog = this.closeDialog.bind(this);
    this.saveDirection = this.saveDirection.bind(this);
  }

  closeDialog() {
    const { odocRequestStore } = this.props;
    odocRequestStore.controlDialogVisible(dialogTypes.USUAL_DIRECTION_DIALOG, false);
  }

  saveDirection() {
    const { onSave, odocRequestStore } = this.props;

    const { directname = '' } = odocRequestStore;

    if (!directname) {
      message.error(getLabel(81968, '名称不能为空！'), 1);
      return;
    }

    onSave && onSave();
  }

  render() {
    const { odocRequestStore } = this.props;
    const { dialogVisible, directname } = odocRequestStore;
    const visible = dialogVisible.get(dialogTypes.USUAL_DIRECTION_DIALOG);

    const items = [];

    items.push(
      <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@dhrpf1@formitem`} {...itemWrapper} label={getLabel(195, '名称')}>
        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@6uhtqp@input`}
          className="required"
          onChange={(v) => {
            odocRequestStore.setMember({ directname: v });
          }}
          value={directname}
        />
      </WeaFormItem>,
    );


    const title = getLabel(507875, '常用去向');
    const style = { width: 500, height: 200 };
    const onCancel = this.closeDialog;
    const buttons = [
      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@ddqc2p@save`} onClick={this.saveDirection} type="primary">{getLabel(86, '保存')}</Button>),
      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5r23me@cancel`} onClick={this.closeDialog}>{getLabel(31129, '取消')}</Button>),
    ];

    const dialogParams = { title, style, visible, onCancel, buttons };

    return (
      <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@4pwf7t`} {...dialogParams}>
        <div className="odoc-usual-dialog">
          {items}
        </div>
      </WeaDialog>
    );
  }
}

export default Main;
